package com.train.common.exception;

import com.train.common.enums.Enums;
import com.train.common.enums.impl.SysExceptionEnums;
import com.train.common.utils.string.FormatterUtils;
import lombok.Getter;

/**
 * 全局异常
 */

public class GlobalException extends RuntimeException {

    @Getter
    private final Integer code;

    private final String message;

    public GlobalException(Enums exceptionEnums, Object... args) {
        this.code = exceptionEnums.getCode();
        String msg = exceptionEnums.getMessage();
        this.message = args.length > 0 ? FormatterUtils.format(msg, args) : msg;
    }

    public GlobalException(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public GlobalException(String message) {
        this.code = SysExceptionEnums.EXP_SERVER.getCode();
        this.message = message;
    }

    @Override
    public String getMessage() {
        return message;
    }
}
